package com.moxie.face.ocr.result;

import android.util.Log;

import com.moxie.face.ocr.result.network.HttpRequestUtils;
import com.moxie.face.ocr.result.network.NetworkCallback;

import java.io.File;

public class CardResultPresenter {
    private static final String TAG = "MXCardResultPresenter";


    public CardResultPresenter() {
        Log.i(TAG, "MXCardResultPresenter" + "***online");
    }


    // 调用OCR检测接口
    public void getOCRInfo(String fid,final INetworkCallback callback,boolean isFront){
        if (!fid.isEmpty()){
            // 魔蝎测试接口
            HttpRequestUtils.postOCRInfo("https://api.51datakey.com/identity/api/gateway", fid, new NetworkCallback() {
                @Override
                public void completed(String response) {
                    callback.callback(response);
                }

                @Override
                public void failed(int httpStatusCode, String error) {
                    super.failed(httpStatusCode, error);
                    callback.fail(error);
                }
            },isFront);
        }
    }


    // 调用活体检测接口
    public void getSelfVerification(String fid,final INetworkCallback callback){
        if (!fid.isEmpty()){
            // 魔蝎测试接口
            HttpRequestUtils.postSelfVerification("https://api.51datakey.com/identity/api/gateway", fid, new NetworkCallback() {
                @Override
                public void completed(String response) {
                    callback.callback(response);
                }

                @Override
                public void failed(int httpStatusCode, String error) {
                    super.failed(httpStatusCode, error);
                    callback.fail(error);
                }
            });
        }
    }

    // 调用上传图片文件接口
    public void uploadPicture(File file,int type,final INetworkCallback callback){
        if (file!=null){
            HttpRequestUtils.postFileRequest("https://res.51datakey.com/resource/api/v1/upload/file",file,type,new NetworkCallback(){

                @Override
                public void completed(String response) {
                    callback.callback(response);
                }

                @Override
                public void failed(int httpStatusCode, String error) {
                    super.failed(httpStatusCode, error);
                    callback.fail(error);
                }
            });
        }
    }

    // 调用静默活体检测接口
    public void getSilentLivingInfo(String fid,final INetworkCallback callback){
        if (!fid.isEmpty()){
            // 魔蝎测试接口
            HttpRequestUtils.postSilentLiving("https://api.51datakey.com/identity/api/gateway", fid, new NetworkCallback() {
                @Override
                public void completed(String response) {
                    callback.callback(response);
                }

                @Override
                public void failed(int httpStatusCode, String error) {
                    super.failed(httpStatusCode, error);
                    callback.fail(error);
                }
            });
        }
    }


    public interface INetworkCallback{
        void callback(String result);

        void fail(String error);
    }

}
